package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/total-waviness-of-numbers-in-range-i/
 * @create 2025/11/23 11:12
 * @since JDK17
 */

public class Solution99 {
    int get(char[] num) {
        if (num.length < 3) {
            return 0;
        }
        int ans = 0, n = num.length - 1;
        for (int i = 1; i < n; i++) {
            if ((num[i] > num[i - 1] && num[i] > num[i + 1]) || (num[i] < num[i + 1] && num[i] < num[i + 1])) {
                ans++;
            }
        }

        return ans;
    }
    public int totalWaviness(int num1, int num2) {
        int ans = 0;
        for (int i = num1; i <= num2; i++) {
            ans += get(String.valueOf(i).toCharArray());
        }

        return ans;
    }
}
